class Solution(object):
    def indexPairs(self, text, words):
        """
        :type text: str
        :type words: List[str]
        :rtype: List[List[int]]
        """
        words_set = set(words)
        n = len(text)
        out = []
        for i in range(n):
            for j in range(i + 1, n + 1):
                if text[i: j] in words_set:
                    out.append([i, j - 1])
        return out


data = Solution()
text = "thestoryofleetcodeandme"
words = ["story", "fleet", "leetcode"]
print(data.indexPairs(text, words))
text = "ababa"
words = ["aba", "ab"]
print(data.indexPairs(text, words))
